﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using cn.sharesdk.unity3d;
public class XTJReplace : MonoBehaviour {
    EginXTJ xtj = EginXTJ.Instance;
    public GameObject copyBtn;
    public GameObject shareBtn;
    public GameObject closeBtn;
    public UILabel roomIdLabel;
    public UILabel topLabel;
    public GameObject goldPattern;
    //金币模式创建内容
    public UILabel goldContent1;
    public UILabel goldContent2;

    private ShareSDK ssdk;

    void Awake()
    {
        ssdk = GameObject.Find("SoundManger").GetComponent<ShareSDK>();
        ssdk.shareHandler = OnShareResultHandler;

        UIEventListener.Get(copyBtn).onClick = ButtonClick;
        UIEventListener.Get(shareBtn).onClick = ButtonClick;
        UIEventListener.Get(closeBtn).onClick = ButtonClick;

    }

    void Start()
    {
        roomIdLabel.text = xtj.roomId.ToString();
        goldContent2.text = xtj.totalRound+ "局";
        if(xtj.level == 0){
            goldContent1.text = "1万";
        }
        else if (xtj.level == 1)
        {
            goldContent1.text = "5万";
        }
        else if (xtj.level == 2)
        {
            goldContent1.text = "10万";
        }

    }

    void ButtonClick(GameObject button)
    {
        if (button.name == "CopyRoomIdBtn")
        {
            UniPasteBoard.SetClipBoardString(roomIdLabel.text);
        }
        else if (button.name == "ShareBtn")
        {

            Debug.Log("分享给微信好友");
            ShareContent content = new ShareContent();
            string downloadUrl = GameObject.Find("UI Root/HallPanel").GetComponent<HallModel>().downloadUrl;
            content.SetText("快来和我一起游戏吧！房间号：" + roomIdLabel.text);
            //content.SetImageUrl("https://f1.webshare.mob.com/code/demo/img/1.jpg");
            content.SetTitle("欢乐掌上棋牌");
            //content.SetTitleUrl("http://www.mob.com");
            content.SetSite("Mob-ShareSDK");
            content.SetSiteUrl("http://www.mob.com");
            content.SetUrl(downloadUrl);
            content.SetComment("欢乐嗨翻天！");
            //content.SetMusicUrl("http://mp3.mwap8.com/destdir/Music/2009/20090601/ZuiXuanMinZuFeng20090601119.mp3");
            content.SetShareType(ContentType.Text);
            ssdk.ShareContent(PlatformType.WeChat, content);

        }
        else if (button.name == "CloseBtn")
        {
            Destroy(gameObject);
        }
    }

    void OnShareResultHandler(int reqID, ResponseState state, PlatformType type, Hashtable result)
    {
        if (state == ResponseState.Success)
        {
            print("share successfully - share result :");
            print(MiniJSON.jsonEncode(result));
        }
        else if (state == ResponseState.Fail)
        {
#if UNITY_ANDROID
            print("fail! throwable stack = " + result["stack"] + "; error msg = " + result["msg"]);
#elif UNITY_IPHONE
			print ("fail! error code = " + result["error_code"] + "; error msg = " + result["error_msg"]);
#endif
        }
        else if (state == ResponseState.Cancel)
        {
            print("cancel !");
        }
    }
	

}
